#include "keyboard.h"

KEYStruct key;

KEYStruct* GetKeyStruct(void)
{
    return &key;
}

//
void ScanKeyboard(void)
{
    switch(key.status)
    {
        case 0: 
			if((P30 == 0) || (P31 == 0) || (P32 == 0) || (P33 == 0)){
				key.status = 1;
			}
            break;
        case 1:
			if(P30 == 0){
				key.value = 7;
				key.status = 2;
			}
			else if(P31 == 0){
				key.value = 6;
				key.status = 2;
			}
			else if(P32 == 0){
				key.value = 5;
				key.status = 2;
			}
			else if(P33 == 0){
				key.value = 4;
				key.status = 2;
			}

			break;
		case 2:
			if((P30 == 1) && (P31 == 1) && (P32 == 1) && (P33 == 1)){
				key.status = 0;
			}
			break; 
    }
}

void InitKeyStruct(void)
{
    key.pFun = ScanKeyboard;
    key.value = 0xFF;
    key.status = 0;
}

